package com.frame.work.frame.deal.device0faa;

import com.alibaba.fastjson.JSONObject;
import com.frame.work.common.util.JsonToMqtt;
import com.frame.work.frame.deal.base.BaseFrame;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 *二路面板
 */
@Data
public class ErLuMianBan_0FAA0602 extends BaseFrame {

    private String switchState;
    private String spreadingType;

    public ErLuMianBan_0FAA0602(String gatewayMac, String data){

        //将基础数据进行处理
        super(gatewayMac,data);

        String switchState_1 = StringUtils.substring(data,data.length() - 4, data.length() - 2);
        String switchState_2 = StringUtils.substring(data,data.length() - 2, data.length());
        this.setSpreadingType( StringUtils.substring(data,38, 40));

        String [] states = {"0",switchState_1,switchState_2};
        String productType = this.getProductType();
        for (int i = 1;i < 3; i++){
            this.setProductType(productType+"_"+i);
            this.setSwitchState(states[i]);

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","DIRECT_CONTROL");
            actions.put("switchState",states[i]);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.mqttLianKongDevice(gatewayMac,json);

        }



    }

}
